package java6;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		IntegerStack stack=new ArrayIntegerStack(sc.nextInt()); 
		for (int i = 0; i < sc.nextInt(); i++) {
			System.out.println(stack.push(sc.nextInt()));
		}
		System.out.println(stack.pop()+","+stack.empty()+","+stack.size());	
		System.out.println(stack.toString());
		for (int i = 0; i < sc.nextInt(); i++) {
			System.out.println(stack.pop());
		}
		System.out.println(stack.pop()+","+stack.empty()+","+stack.size());	
		System.out.println(stack.toString());
	}

}
